package com.cosina.game.crystallight.model.profile;

import com.cosina.game.crystallight.dao.ProfileDAOFacade;

public class ProfileManager {
	private static Profile currentProfile = null;
	
	public static Profile getCurrentProfile(){
		if(null == currentProfile){
			int selectNameIndex = ProfileDAOFacade.getCurrentProfileNameIndex();
			if(-1 != selectNameIndex){
				if(getAllName()[selectNameIndex].equals(EMPTY_PROFILE)){
					return null;
				}
				currentProfile = ProfileDAOFacade.loadProfile( getAllName()[selectNameIndex]);
			}
		}
		return currentProfile;
	}
	
	public static void setCurrentProfile(int index){
		ProfileDAOFacade.saveCurrentProfileNameIndex(index);
		currentProfile = ProfileDAOFacade.loadProfile(getAllName()[index]);
	}
	public static void removeCurrentProfile(){
		currentProfile = null;
	}
	
	public static final String EMPTY_PROFILE = "empty";
	public static String[] getAllName(){
		return ProfileDAOFacade.getProfileNames();
	}
}
